/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package projetointegrado;
import sun.audio.*;
import java.io.*;
import javax.sound.midi.MidiSystem;
import javax.sound.midi.Sequence;
import javax.sound.midi.Sequencer;

/**
 *
 * @author Thor
 */
public class Sounds {
    AudioStream backgroundMusic;
            AudioData musicData;
            AudioPlayer musicPlayer = AudioPlayer.player;
            ContinuousAudioDataStream loop = null;
            Sequence sequence ;
            Sequencer sequencer;

    public void playIntro(){
        try {
                backgroundMusic = new AudioStream(new FileInputStream("src/sounds/intro.wav"));
                musicData = backgroundMusic.getData();
                loop = new ContinuousAudioDataStream(musicData);
                musicPlayer.start(loop);
            } catch (IOException error) { System.out.println(error);
            }
    }
    public void playIntroMidi(){
        try {
                sequence = MidiSystem.getSequence(new File("src/sounds/intro.mid"));
                sequencer = MidiSystem.getSequencer();
                sequencer.open();
                sequencer.setSequence(sequence);
                sequencer.start();
            } catch (Exception error) { System.out.println(error);
            }
    }
    public void playMegaManMidi(){
        try {
                sequence = MidiSystem.getSequence(new File("src/sounds/megaMan2.mid"));
                sequencer = MidiSystem.getSequencer();
                sequencer.open();
                sequencer.setSequence(sequence);
                sequencer.start();
            } catch (Exception error) { System.out.println(error);
            }
    }
    public void playBattle(){
        try {
                sequence = MidiSystem.getSequence(new File("src/sounds/battle.mid"));
                sequencer = MidiSystem.getSequencer();
                sequencer.open();
                sequencer.setSequence(sequence);
                sequencer.start();
            } catch (Exception error) { System.out.println(error);
            }
    }
    public void playTravel(){
        try {
                backgroundMusic = new AudioStream(new FileInputStream("src/sounds/travel.wav"));
                musicData = backgroundMusic.getData();
                loop = new ContinuousAudioDataStream(musicData);
                musicPlayer.start(loop);
            } catch (IOException error) { System.out.println(error);
            }
    }
    public void playHeal(){
        try {
                sequence = MidiSystem.getSequence(new File("src/sounds/heal.mid"));
                sequencer = MidiSystem.getSequencer();
                sequencer.open();
                sequencer.setSequence(sequence);
                sequencer.start();
            } catch (Exception error) { System.out.println(error);
            }
    }
    public void playBlocoB(){
        try {
                sequence = MidiSystem.getSequence(new File("src/sounds/blocoB.mid"));
                sequencer = MidiSystem.getSequencer();
                sequencer.open();
                sequencer.setSequence(sequence);
                sequencer.start();
            } catch (Exception error) { System.out.println(error);
            }
    }
    public void playBlocoE(){
        try {
                sequence = MidiSystem.getSequence(new File("src/sounds/blocoE.mid"));
                sequencer = MidiSystem.getSequencer();
                sequencer.open();
                sequencer.setSequence(sequence);
                sequencer.start();
            } catch (Exception error) { System.out.println(error);
            }
    }
    public void playMapa(){
        try {
                sequence = MidiSystem.getSequence(new File("src/sounds/mapa.mid"));
                sequencer = MidiSystem.getSequencer();
                sequencer.open();
                sequencer.setSequence(sequence);
                sequencer.start();
            } catch (Exception error) { System.out.println(error);
            }
    }
    public void playGameOver(){
        try {
                sequence = MidiSystem.getSequence(new File("src/sounds/gameOver.mid"));
                sequencer = MidiSystem.getSequencer();
                sequencer.open();
                sequencer.setSequence(sequence);
                sequencer.start();
            } catch (Exception error) { System.out.println(error);
            }
    }
    public void stopAll(){
        musicPlayer.stop(loop);
    }
    public void stopMidi(){
        sequencer.stop();
    }
    
}
